﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HFController;

namespace HFWebManage.Instruments
{
    public partial class InstrumentsList : HFController.BagePages
    {
        /// <summary>
        /// 列表
        /// </summary>
        public List<hf.Model.Instruments> list = new List<hf.Model.Instruments>();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.checkAdminIsLogin();
            if (!Page.IsPostBack)
            {
                string PageStr = "";
                list = InstrumentsController.getController().getInstrumentsList(out PageStr);
                pager.Text = PageStr;

                string Action = this.GetQuery("action");
                switch (Action)
                {
                    case "delete": //单个删除
                        int ID = int.Parse(this.GetQuery("ID"));
                        InstrumentsController.getController().doDelegeInstruments(ID);
                        break;
                    case "deleteall": //批量删除
                        string IDS = this.GetAll("cid1");
                        InstrumentsController.getController().doDelegeInstruments(IDS.Split(','));
                        break;
                    case "seach":
                        string keys = this.GetQuery("keys");
                        int total = 0;
                        int PageNumber = 1;
                        list = InstrumentsController.getController().getInstrumentsList(10 ,1 ,"Title like '%" + keys + "%'" ,out total);
                        if (this.GetQuery("Page") != "")
                        {
                            PageNumber = int.Parse(this.GetQuery("Page"));
                        }
                        pager.Text = LLL.Pager.TrunPageHtmlCode(10, PageNumber, total, "");
                        break;
                }
            }
        }
        /// <summary>
        /// 得到文书大类名称
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string getInstrumentsBigClass(int ID)
        {
            hf.Model.InstrumentsBigClass model = InstrumentsController.getController().getInstrumentsBigClassModel(ID);
            return model.InstrumentsName;
        }

        /// <summary>
        /// 得到文书小分类名称
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string getInstrumentsSmallClass(int ID)
        {
            hf.Model.InstrumentsSmallClass model = InstrumentsController.getController().getInstrumentsSmallClassModel(ID);
            return model.InstrumentsName;
        }

        /// <summary>
        /// 得到文书类型名称
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string getInstrumentsFileType(int ID)
        {
            hf.Model.InstrumentsFileType model = InstrumentsController.getController().getInstrumentsFileTypeModel(ID);
            return model.TypeName;
        }

        /// <summary>
        /// 快速搜索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("InstrumentsList.aspx?action=seach&keys=" + keys.Text);
        }
    }
}